#include<iostream>

using namespace std;

const int N = 1000 + 10; 

int n,m;
int c[N],r[N];
int st[N][N];
char grid[N][N];
int mov[4][2] = {0,1,0,-1,1,0,-1,0};
int vis[N][N];

void dfs(int i, int j)
{
	grid[i][j] = '.';
	for(int k=0; k<4; k++)
	{
		int x = i + mov[k][0];
		int y = j + mov[k][1];
		if(grid[x][y] == '#') dfs(x,y); 
	}
}


int main()
{
	cin>>n>>m;
	for(int i=1; i<=n; i++)
	{
		scanf("%s",grid[i]+1);
		for(int j=1; j<=m; j++)
		{
			if(grid[i][j] == '#') r[i]++,c[j]++;
		}
	}
	for(int i=1; i<=n; i++)
		for(int j=1; j<=m; j++)
			if(r[i] == 0 && c[j] == 0)
				st[i][j] = 1;
	for(int i=1; i<=n; i++)
	{
		int cnt = 0;
		for(int j=1; j<=m; j++)
		{
			if(st[i][j]) cnt++;
		}
		if(!cnt && !r[i]) 
		{
			puts("-1");
			return 0;
		}
		int num = r[i];
		for(int j=1; j<=m; j++)
		{
			if(grid[i][j] == '.' && num && num != r[i])
			{
				puts("-1");
				return 0;
			}
			else if(grid[i][j] == '#') num--;
		}
	}
	for(int j=1; j<=m; j++)
	{
		int cnt = 0;
		for(int i=1; i<=n; i++)
		{
			if(st[i][j]) cnt++;
		}
		if(!cnt && !c[j]) 
		{
			puts("-1");
			return 0;
		}
		int num = c[j];
		for(int i=1; i<=n; i++)
		{
			if(grid[i][j] == '.' && num && num != c[j])
			{
				puts("-1");
				return 0;
			}
			else if(grid[i][j] == '#') num--;
		}		
	}
	int ans = 0;
	for(int i=1; i<=n; i++)
	{
		for(int j=1; j<=m; j++)
		{
			if(grid[i][j] == '#') 
			{
				ans++;
				dfs(i,j);
			}
		}
	}
	cout<<ans;
	return 0;
}
